home *** CD-ROM | disk | FTP | other *** search
/ Java Programmer's Toolkit / Java Programmer's Toolkit.iso / src / java / lang / boolea~1.jav < prev    next >
Encoding:
Text File  |  1996-01-12  |  3.6 KB  |  133 lines

  1. /*
  2.  * @(#)Boolean.java    1.18 95/11/13  
  3.  *
  4.  * Copyright (c) 1994 Sun Microsystems, Inc. All Rights Reserved.
  5.  *
  6.  * Permission to use, copy, modify, and distribute this software
  7.  * and its documentation for NON-COMMERCIAL purposes and without
  8.  * fee is hereby granted provided that this copyright notice
  9.  * appears in all copies. Please refer to the file "copyright.html"
  10.  * for further important copyright and licensing information.
  11.  *
  12.  * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF
  13.  * THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
  14.  * TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
  15.  * PARTICULAR PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR
  16.  * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
  17.  * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES.
  18.  */
  19.  
  20. package java.lang;
  21.  
  22. /**
  23.  * The Boolean class provides an object wrapper for Boolean data values, and 
  24.  * serves as a place for boolean-oriented operations.
  25.  * A wrapper is useful because most of Java's utility classes require the use
  26.  * of objects.  Since booleans are not objects in Java, they need to be
  27.  * "wrapped" in a Boolean instance. 
  28.  * @version     1.18, 11/13/95
  29.  * @author    Arthur van Hoff
  30.  */
  31. public final
  32. class Boolean {
  33.     /** 
  34.      *  Assigns this Boolean to be true.
  35.      */
  36.     public static final Boolean TRUE = new Boolean(true);
  37.     /** 
  38.      * Assigns this Boolean to be false.
  39.      */
  40.     public static final Boolean FALSE = new Boolean(false);
  41.  
  42.     /**
  43.      * The minimum value a Charater can have.  The lowest minimum value an
  44.      * Integer can have is '\u0000'.
  45.      */
  46.     public static final char   MIN_VALUE = '\u0000';
  47.  
  48.     /**
  49.      * The maximum value a Character can have.  The greatest maximum value an
  50.      * Integer can have is '\uffff'.
  51.      */
  52.     public static final char   MAX_VALUE = '\uffff';
  53.     
  54.     /**
  55.      * The value of the Boolean.
  56.      */
  57.     private boolean value;
  58.  
  59.     /**
  60.      * Constructs a Boolean object initialized to the specified boolean 
  61.      * value.
  62.      * @param value the value of the boolean
  63.      */
  64.     public Boolean(boolean value) {
  65.     this.value = value;
  66.     }
  67.  
  68.     /**
  69.      * Constructs a Boolean object initialized to the value specified by the
  70.      * String parameter. 
  71.      * @param s        the String to be converted to a Boolean
  72.      */
  73.     public Boolean(String s) {
  74.     this((s != null) && s.toLowerCase().equals("true"));
  75.     }
  76.  
  77.     /**
  78.      * Returns the value of this Boolean object as a boolean.
  79.      */
  80.     public boolean booleanValue() {
  81.     return value;
  82.     }
  83.  
  84.     /**
  85.      * Returns the boolean value represented by the specified String.
  86.      * @param s        the String to be parsed
  87.      */
  88.     public static Boolean valueOf(String s) {
  89.     return new Boolean((s != null) && s.toLowerCase().equals("true"));
  90.     }
  91.  
  92.     /**
  93.      * Returns a new String object representing this Boolean's value.
  94.      */
  95.     public String toString() {
  96.     return value ? "true" : "false";
  97.     }
  98.  
  99.     /**
  100.      * Returns a hashcode for this Boolean.
  101.      */
  102.     public int hashCode() {
  103.     return value ? 1231 : 1237;
  104.     }
  105.  
  106.     /**
  107.      * Compares this object against the specified object.
  108.      * @param obj        the object to compare with
  109.      * @return         true if the objects are the same; false otherwise.
  110.      */
  111.     public boolean equals(Object obj) {
  112.     if ((obj != null) && (obj instanceof Boolean)) {
  113.         return value == ((Boolean)obj).booleanValue();
  114.     } 
  115.     return false;
  116.     }
  117.  
  118.     /**
  119.      * Gets a Boolean from the properties.
  120.      * @param name the property name.
  121.      */
  122.     public static boolean getBoolean(String name) {
  123.     return "true".equals(System.getProperty(name));
  124.     }
  125. }
  126.  
  127.  
  128.  
  129.  
  130.  
  131.  
  132.  
  133.